﻿@page "/users/{Id}/roles"
@attribute [MustHavePermission(FSHAction.View, FSHResource.UserRoles)]

@inject IStringLocalizer<UserRoles> L

<FshTitle Title="@_title" Description="@_description" />

@if (!_loaded)
{
    <MudProgressCircular Color="Color.Primary" Indeterminate="true" />
}
else
{
    <MudTable Hover="true" Elevation="25" Items="_userRolesList" Filter="new Func<UserRoleDto, bool>(Search)">
        <ToolBarContent>
            <div class="justify-center mud-text-align-center">
                <MudButton Variant="Variant.Filled" Color="Color.Info" Class="ml-auto" StartIcon="@Icons.Material.Filled.ArrowBack" Link="/users">
                    @L["Back"]
                </MudButton>
                @if (_canEditUsers)
                {
                    <MudButton Variant="Variant.Filled" Color="Color.Primary" Class="ml-auto" OnClick="SaveAsync" StartIcon="@Icons.Material.Filled.Save"
                        ButtonType="ButtonType.Submit" Style="margin-left: 5px!important;">
                        @L["Update"]
                    </MudButton>
                }
            </div>
            <MudSpacer />
            @if (_canSearchRoles)
            {
                <MudTextField @bind-Value="_searchString" Immediate="true" FullWidth=false
                    Placeholder="@L["Search For User Roles"]" Adornment="Adornment.End"
                    AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0 mb-3">
                </MudTextField>
            }
        </ToolBarContent>
        <HeaderContent>
            <MudTh>
                <MudTableSortLabel SortBy="new Func<UserRoleDto, object?>(x => x.RoleName)">@L["Role Name"]
                </MudTableSortLabel>
            </MudTh>
            <MudTh>
                <MudTableSortLabel SortBy="new Func<UserRoleDto, object?>(x => x.Description)">@L["Description"]
                </MudTableSortLabel>
            </MudTh>
            <MudTh>
                <MudTableSortLabel SortBy="new Func<UserRoleDto, object>(x => x.Enabled)">@L["Status"]
                </MudTableSortLabel>
            </MudTh>
        </HeaderContent>
        <RowTemplate>
            <MudTd DataLabel="@L["Role Name"]">
                <MudHighlighter Text="@context.RoleName" HighlightedText="@_searchString" />
            </MudTd>
            <MudTd DataLabel="@L["Description"]">
                <MudHighlighter Text="@context.Description" HighlightedText="@_searchString" />
            </MudTd>
            <MudTd DataLabel="Role">
                <MudCheckBox @bind-Checked="@context.Enabled" Disabled="@(!_canEditUsers)" Color="Color.Secondary">
                </MudCheckBox>
            </MudTd>
        </RowTemplate>
        <PagerContent>
            <TablePager />
        </PagerContent>
    </MudTable>
}